<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 用户类  
 */
class AdminStatistic extends CI_Controller{

    public function __construct(){
        parent::__construct();
        $this->load->library('request');  //自定义
        $this->load->library('response'); //自定义
        $this->load->library('session'); //公共 
        $reqOrigin = isset($_SERVER['HTTP_ORIGIN'])?$_SERVER['HTTP_ORIGIN']:'';
        $configOrigin = $this->config->item("allowOrigin");
        if(in_array($reqOrigin,$configOrigin)){
            header("Access-Control-Allow-Credentials:true");
            header("Access-Control-Allow-Headers:Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild");
            header("Access-Control-Allow-Methods:PUT, POST, GET, DELETE, OPTIONS");
            header("Access-Control-Allow-Origin:$reqOrigin"); 
        }
    }

    /**
     * [loginStatus description]
     * @return [type] [description]
     */
    private function loginStatus(){
        if(isset($this->session->admin_user_id) && $this->session->admin_user_id){
            return array("admin_user_id"=>$this->session->admin_user_id,"status"=>0);
        }
        else{
            return array("status"=>2006);
        }

    }
 
     /**
     * [statiscIndex description]
     * @return [type] [description]
     */
    public function statisticIndex(){
        if($this->input->method()=="get"){       
            //1登陆状态
            $login = $this->loginStatus();
            if($login['status']){
                $this->response->sendData($login['status']);return;
            }
            $admin_user_id = $login['admin_user_id'];
            // echo $admin_user_id;exit;
            //2获取数据
            $data = $this->request->getGetData(['syearmonth','eyearmonth']);
            log_message('info', 'AdminStatisc/statisticIndex,data:'.json_encode($data));     
           
            $this->load->model("taskModel");
            //3查询基本的任务数据
            $ret = array();
            $ret['out_data']['total'] = $this->taskModel->adminTaskStatistic();   
            $ret['out_data']['complete'] = $this->taskModel->adminTaskStatistic(2);   //包含正常完成+取消
            $ret['out_data']['develop'] = $this->taskModel->adminTaskStatistic(1);   
            $ret['out_data']['cancel'] = $this->taskModel->adminTaskObtainStatistic(7);   //取消了
            // var_dump($ret);exit;
            //4金钱流入流出
            $statistic['statistic'] = $this->taskModel->adminTaskStatisticFound($data);
            //5          
            $statistic['incomelist'] = $this->taskModel->adminTaskStatisticFoundList($data,1);          
            $statistic['paylist'] = $this->taskModel->adminTaskStatisticFoundList($data,2);          
            
            $this->response->sendData(0,$statistic,$ret['out_data']);return;
        }
        else{
            $status = 1001;
        }
        $this->response->sendData($status);

    }
    // /**
    //  * [statiscIndex description]
    //  * @return [type] [description]
    //  */
    // public function statiscIndex(){
    //     if($this->input->method()=="get"){       
    //         //1登陆状态
    //         $login = $this->loginStatus();
    //         if($login['status']){
    //             $this->response->sendData($login['status']);return;
    //         }
    //         $admin_user_id = $login['admin_user_id'];
    //         // echo $admin_user_id;exit;
    //         //2获取数据
    //         $data = $this->request->getGetData(["page","size",'keyword','obtainStatus']);
    //         log_message('info', 'AdminStatisc/statiscIndex,data:'.json_encode($data));     
    //         if(!$data['page'] || !$data['size'] ){
    //             $this->response->sendData(1000);return;
    //         }
    //         //3查询
    //         $this->load->model("taskModel");
    //         $ret = $this->taskModel->adminTaskObtainList($data);          
    //         //4查询基础的统计
    //         $ret['out_data']['typeOne'] = $this->taskModel->adminTaskObtainStatistic(0);   
    //         $ret['out_data']['typeTwo'] = $this->taskModel->adminTaskObtainStatistic(1);   
    //         $ret['out_data']['typeThree'] = $this->taskModel->adminTaskObtainStatistic(6);   
    //         $ret['out_data']['typeFour'] = $this->taskModel->adminTaskObtainStatistic(3);   
    //         $ret['out_data']['typeFive'] = 0;//$this->taskModel->adminTaskObtainStatistic(5);   
            
    //         $this->response->sendData($ret['status'],$ret['data'],$ret['out_data']);return;
    //     }
    //     else{
    //         $status = 1001;
    //     }
    //     $this->response->sendData($status);

    // }
 
}
